---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-promu-artifact
from: {{ $.Images.BASE_GOLANG_18_ALPINE_DEV }}
mount:
- fromPath: ~/go-pkg-cache
  to: /go/pkg
shell:
  install:
  - export GOPROXY={{ $.GOPROXY }} CGO_ENABLED=0 GOOS=linux GOARCH=amd64
  - git clone --depth 1 --branch v0.14.0 {{ $.SOURCE_REPO }}/prometheus/promu.git /promu
  - cd /promu
  - go build -ldflags="-s -w" -o promu ./main.go
---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
from: {{ $.Images.BASE_GOLANG_21_BULLSEYE_DEV }}
fromCacheVersion: 2024022701
mount:
- fromPath: ~/go-pkg-cache
  to: /go/pkg
import:
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-promu-artifact
  add: /promu/promu
  to: /bin/promu
  before: install
git:
- add: /{{ $.ModulePath }}modules/300-{{ $.ModuleName }}/images/{{ $.ImageName }}
  to: /patches
  includePaths:
  - '**/*.patch'
  stageDependencies:
    install:
    - '**/*'
shell:
  install:
  - export NODE_MAJOR=20
  - export GOPROXY={{ $.GOPROXY }} CGO_ENABLED=0 GOOS=linux GOARCH=amd64 PROMETHEUS_VERSION=v2.45.2
  - git clone -b "${PROMETHEUS_VERSION}" --single-branch {{ $.SOURCE_REPO }}/prometheus/prometheus-deps
  - mkdir /prometheus && cd /prometheus
  - git clone -b "${PROMETHEUS_VERSION}" --single-branch {{ $.SOURCE_REPO }}/prometheus/prometheus
  - cd /prometheus/prometheus/web/ui
  - mv /prometheus-deps/* .
  - npm run build
  - cd /prometheus/prometheus
  - scripts/compress_assets.sh
  - go mod tidy
  - find /patches -name '*.patch' | xargs git apply --verbose
  - go generate -tags plugins ./plugins
  - /bin/promu build --prefix /prometheus/prometheus
  - mkdir -p /consoles
  - cp /prometheus/prometheus/consoles/* /consoles
  - cp /prometheus/prometheus/console_libraries/* /consoles
  - mkdir -p /etc
  - cp /prometheus/prometheus/documentation/examples/prometheus.yml /etc
  - cp /prometheus/prometheus/console_libraries/* /etc
  - mkdir /empty
  - chown -R 64535:64535 /empty
  - chown -R 64535:64535 /prometheus/
  - chown -R 64535:64535 /etc/
  - chown -R 64535:64535 /consoles/
  - chmod 0700 /prometheus/prometheus/prometheus
  - chmod 0700 /prometheus/prometheus/promtool
---
{{ $binariesList := "/usr/bin/curl /bin/sh /bin/df" }}
---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-binaries-artifact
from: {{ $.Images.BASE_ALT_DEV }}
shell:
  install:
    - /binary_replace.sh -i "{{ $binariesList }}" -o /relocate
---
image: {{ $.ModuleName }}/{{ $.ImageName }}
fromImage: common/distroless
fromCacheVersion: 2024022701
import:
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /prometheus/prometheus/prometheus
  to: /bin/prometheus
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /prometheus/prometheus/promtool
  to: /bin/promtool
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /prometheus/prometheus/console_libraries/
  to: /usr/share/prometheus/console_libraries
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /consoles/
  to: /usr/share/prometheus/consoles
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /etc/
  to: /etc/prometheus
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact
  add: /empty/
  to: /prometheus
  before: setup
- artifact: {{ $.ModuleName }}/{{ $.ImageName }}-binaries-artifact
  add: /relocate
  to: /
  before: install
  includePaths:
  - '**/*'
docker:
  EXPOSE:
  - "9090"
  VOLUME:
  - "/prometheus"
  WORKDIR: "/prometheus"
  ENTRYPOINT:
  - "/bin/prometheus"
  CMD:
  - "--config.file=/etc/prometheus/prometheus.yml"
  - "--storage.tsdb.path=/prometheus"
  - "--web.console.libraries=/usr/share/prometheus/console_libraries"
  - "--web.console.templates=/usr/share/prometheus/consoles"
